﻿using CinemaMaestro.BusinessLayer.Contracts;
using CinemaMaestro.Common.IocContainer;
using CinemaMaestro.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace CinemaMaestro.RestApi.Controllers
{
    [Authorize]
    public class ReservationsController : ApiController
    {

        [HttpGet]
        [Route("api/reservationForScreening/{screeningId}")]
        public IHttpActionResult GetReservationsForScreening(int screeningId)
        {
            var businessUoW = Resolver.Get<IBusinessObjectFactory>();

            var reservations = businessUoW.Reservations.Read()
                .Where(x => x.Screening.Id == screeningId).ToList();

            List<ReservationViewModel> models = new List<ReservationViewModel>();

            foreach (var model in reservations)
            {
                ReservationViewModel reservation = model;
                models.Add(reservation);
            }

            return Ok(models);
        }

    }
}
